package com.niii.message.controller;

import com.niii.message.common.Result;
import com.niii.message.common.StatusCode;
import com.niii.message.pojo.Msg;
import com.niii.message.pojo.WebSocketServer;
import com.niii.message.service.messageService;
import io.swagger.annotations.Api;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@Api(tags = "menu",description = "消息服务")
@RestController
@RequestMapping(value = "/msg")
@CrossOrigin(origins ="*" , maxAge = 3600)
public class messageController {

    @Autowired
    private WebSocketServer webSocketServer;

    @Autowired
    private messageService messageService;

    @RequestMapping(method = RequestMethod.POST,value = "/sendMsg")

    public Result sendMsg(@RequestBody Msg msg){
        messageService.send(msg);
        return new Result(true, StatusCode.OK,"发送成功");
    }

    @RequestMapping(method = RequestMethod.POST,value = "/send")
    public Result test() throws IOException {
        webSocketServer.onMessage("123123123");
        return new Result(true, StatusCode.OK,"发送成功");
    }


}
